package com.xiaomi.back.Interceptor;

import com.xiaomi.pojo.Business;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)throws Exception {

        HttpSession session = request.getSession() ;
        Business loginUser = (Business) session.getAttribute("business") ;
        if(loginUser == null) {
            response.sendRedirect("/back_login.jsp");
            return false ;
        }

        return true;
    }

}
